package edu.zju.gis.cky.util;

import org.gdal.ogr.DataSource;
import org.gdal.ogr.Feature;
import org.gdal.ogr.Geometry;
import org.gdal.ogr.ogr;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Zhou Yuquan
 * @version 1.0, 2022-01-10
 */
public class ShpHelper {

    public static List<Geometry> read(String path) {
        List<Geometry> geometries = new ArrayList<>();

        // GDAL配置
        ogr.RegisterAll();

        // 打开Shp文件
        DataSource ds = ogr.Open(path, 0);

        // 读取layer
        org.gdal.ogr.Layer player = ds.GetLayer(0);

        while (true) {
            Feature feature = player.GetNextFeature();
            if (feature == null) {
                break;
            }
            geometries.add(feature.GetGeometryRef());
        }

        return geometries;
    }

}
